package baseTest;

import java.util.Arrays;

public class moveZeroes {
    public static void main(String[] args) {
        int[] nums ={0,1,0,0,3,12};
        process(nums);
        Arrays.stream(nums).forEach(System.out::print);
    }

    public static void process(int[] nums){
        int pre = 0;
        int next = 1;
        while (next < nums.length){
            if (nums[pre] == 0 && nums[next] != 0){
                swap(nums,pre,next);
                pre++;
                next++;
            } else if (nums[pre] == 0 && nums[next] == 0){
                next++;
            } else {
                pre++;
                next++;
            }
        }
    }

    public static void swap(int[] nums,int n,int m){
        int temp = nums[n];
        nums[n] = nums[m];
        nums[m] = temp;
    }
}
